package d0318;

import java.util.Date;

public class JoinTester implements Runnable {
    private String name;

    public JoinTester() {}

    public JoinTester(String name){
        this.name= name;
    }

    @Override
    public void run(){
        System.out.println(name+"线程开始于："+ new Date());
        try {
            Thread.sleep(3000);
            if(this.name == "two") {
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(name+"线程结束于："+ new Date());
    }

    public static void main(String[] args) {
        Thread thread1 = new Thread(new JoinTester("one"));
        Thread thread2 = new Thread(new JoinTester("two"));
        thread1.start();
        thread2.start();
        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("主线程结束");
    }
}